{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "63233b14",
   "metadata": {},
   "source": [
    "* 日期：2022-09-21 week05（周三）\n",
    "* 课程：python\n",
    "* 记录人：lishengqing"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ca6cb39",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    ">1.数值（number）\n",
    ">>A.定义  \n",
    ">>B.方法\n",
    "\n",
    ">2.字符串（string）\n",
    ">>A.定义  \n",
    ">>B.方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3570235",
   "metadata": {},
   "source": [
    "## 1.数值\n",
    ">1.对数值进行分类\n",
    ">>1. 整数(int)\n",
    ">>2. 浮点型(float)\n",
    ">>3. 复数(complex)\n",
    "> 2.数值的运算法则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e759dee6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 整型\n",
    "a = 99\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8d42c970",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# 浮点型\n",
    "b = 99.9\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "334a68db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "198.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "c = a+b\n",
    "print(c,type (c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b4d12d2a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "# 复数(虚数)\n",
    "d = 2+3j\n",
    "print(d,type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29664e66",
   "metadata": {},
   "source": [
    "# 字符串（str）\n",
    "> 1.定义  \n",
    "> 2.方法\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "31e24bad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = 'Alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a32b3460",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can't multiply sequence by non-int of type 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [3]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m a \u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m18\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m      2\u001b[0m b \u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m22\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m----> 3\u001b[0m c \u001b[38;5;241m=\u001b[39m \u001b[43ma\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mb\u001b[49m\n",
      "\u001b[1;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'str'"
     ]
    }
   ],
   "source": [
    "a ='18'\n",
    "b ='22'\n",
    "c = a * b "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "35dfcbb3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18 18\n",
      "<class 'int'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a = 18\n",
    "b ='18'\n",
    "print(a,b)\n",
    "print(type(a),type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c4494667",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (3605583289.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [12]\u001b[1;36m\u001b[0m\n\u001b[1;33m    'dosen't'\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 关于单引号和双引号\n",
    "'dosen't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "dfa2c6f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#解决方案1\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "916e4862",
   "metadata": {},
   "outputs": [],
   "source": [
    "#解决方案2  \\后面的内容是\"符号\"，转义，\\自动消失\n",
    "'dosent\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89377b33",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 正则表达式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bcb537e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"hello\n",
    "world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "491b748a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三个引号，可以包含任何文本\n",
    "#作用：\n",
    "#1.保持原数据的结构，包含符号换行等。\n",
    "#2. 可以用来做代码注释。\n",
    "NFU_招投标_HTML = \"\"\" \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2b40795",
   "metadata": {},
   "outputs": [],
   "source": [
    "### 三个引号来代码注释\n",
    "import random\n",
    "import time\n",
    "\n",
    "print(\"hello world!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f091a02",
   "metadata": {},
   "source": [
    "### 2.1 字符串的运算法则\n",
    ">1.字符串的拼接  \n",
    ">2.<font color=\"red\">字符串的有序性</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a4355fd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'helloworld'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#字符串\n",
    "\"hello\" + \"world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "51a1049f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好，Alex\n",
      "你好，Marry\n"
     ]
    }
   ],
   "source": [
    "# 实践\n",
    "text = \"你好，\"\n",
    "for i in [\"Alex\",\"Marry\"]:\n",
    "    result = text+i\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdb7fce0",
   "metadata": {},
   "source": [
    "### 取值\n",
    ">1.取单个值  \n",
    ">2.切片，取多个连续的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "1ef1d929",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的有序性\n",
    "地址 = \"广州市从化区温泉大道882号广州南方学院\" "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "d29c1e5a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "b892e06f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "525bab15",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化区'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "329cefda",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "存在 广州 这个文本\n",
      "院\n",
      "存在 广州 这个文本\n",
      "号\n"
     ]
    }
   ],
   "source": [
    "# 实践：请检查 广州是否在 地址 里面？\n",
    "# 检查i[index]是否是广，然后判断i[index+1]下一个索引值的内容是否是州\n",
    "\n",
    "# 方法1: enumerate:枚举\n",
    "for index,value in enumerate(地址):\n",
    "    if value == \"广\": \n",
    "        if 地址[index+1] == \"州\":\n",
    "            print(\"存在 广州 这个文本\")\n",
    "            \n",
    "            print(地址[index-1])\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "4394c6d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 方法2：in 可以查询成员变量,但只能查询是否存在\n",
    "print(\"广州\" in 地址)\n",
    "print(\"Alex\" in 地址)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "f64f6556",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 回去课后学习[字符串方法]\n",
    "## 1. 首字母变大写\n",
    "## 2. 检查字符出现的次数\n",
    "print(\"alex\".capitalize())\n",
    "地址.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c866183",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
